package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HotelFacility;
import com.ruoyi.system.service.IHotelFacilityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 酒店设施Controller
 * 
 * @author ruoyi
 * @date 2024-03-19
 */
@Controller
@RequestMapping("/system/facility")
public class HotelFacilityController extends BaseController
{
    private String prefix = "system/facility";

    @Autowired
    private IHotelFacilityService hotelFacilityService;

    @RequiresPermissions("system:facility:view")
    @GetMapping()
    public String facility()
    {
        return prefix + "/facility";
    }

    /**
     * 查询酒店设施列表
     */
    @RequiresPermissions("system:facility:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HotelFacility hotelFacility)
    {
        startPage();
        List<HotelFacility> list = hotelFacilityService.selectHotelFacilityList(hotelFacility);
        return getDataTable(list);
    }

    /**
     * 导出酒店设施列表
     */
    @RequiresPermissions("system:facility:export")
    @Log(title = "酒店设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HotelFacility hotelFacility)
    {
        List<HotelFacility> list = hotelFacilityService.selectHotelFacilityList(hotelFacility);
        ExcelUtil<HotelFacility> util = new ExcelUtil<HotelFacility>(HotelFacility.class);
        return util.exportExcel(list, "酒店设施数据");
    }

    /**
     * 新增酒店设施
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存酒店设施
     */
    @RequiresPermissions("system:facility:add")
    @Log(title = "酒店设施", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HotelFacility hotelFacility)
    {
        return toAjax(hotelFacilityService.insertHotelFacility(hotelFacility));
    }

    /**
     * 修改酒店设施
     */
    @RequiresPermissions("system:facility:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HotelFacility hotelFacility = hotelFacilityService.selectHotelFacilityById(id);
        mmap.put("hotelFacility", hotelFacility);
        return prefix + "/edit";
    }

    /**
     * 修改保存酒店设施
     */
    @RequiresPermissions("system:facility:edit")
    @Log(title = "酒店设施", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HotelFacility hotelFacility)
    {
        return toAjax(hotelFacilityService.updateHotelFacility(hotelFacility));
    }

    /**
     * 删除酒店设施
     */
    @RequiresPermissions("system:facility:remove")
    @Log(title = "酒店设施", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hotelFacilityService.deleteHotelFacilityByIds(ids));
    }
}
